@ECHO OFF
@ECHO OneReality 'MyGoals' Sample Project
@ECHO -----------------------------------------------------
@ECHO Clearbas.cmd
@ECHO Tears down the SQL Server 2005 Database
@ECHO on the specified instance and schema.
@ECHO .
@ECHO .
@ECHO Syntax: clearbas MYPC\SQLEXPRESS MySchema
@ECHO .

:CheckMachine
@ECHO .
@ECHO Checking for specified Machine Name...
IF %1 == "" GOTO :SetDefaultMachine

:SetCustomMachine
@ECHO Machine Name found.  Using '%1'.
@ECHO .
SET DB_MACHINE=%1
GOTO :CheckSchema

:SetDefaultMachine
@ECHO Machine Name not found.  Using 'JOEMU-VS1'.
@ECHO .
SET DB_MACHINE=JOEMU-VS1
GOTO :CheckSchema

:CheckSchema
@ECHO .
@ECHO Checking for specified Schema Name...
IF %2 == "" GOTO :SetDefaultSchema

:SetCustomSchema
@ECHO Machine Name found.  Using '%2'.
@ECHO .
SET DB_SCHEMA=%2
GOTO :CheckMachineDone

:SetDefaultSchema
@ECHO Schema Name not found.  Using 'MyGoals'.
@ECHO .
SET DB_SCHEMA=MyGoals
GOTO :CheckMachineDone

:CheckMachineDone

:RunScripts
@ECHO .
@ECHO Running Scripts...
@ECHO .

PUSHD Procedures

@ECHO .
@ECHO Step 1: Dropping Stored Procedures
sqlcmd -E -i DropProcs.sql -S %1 -d %2

POPD

@ECHO Step 2: Dropping Indexes.
sqlcmd -E -i IndexDrop.sql -S %1 -d %2

@ECHO Step 3: Dropping References.
sqlcmd -E -i ReferenceDrop.sql -S %1 -d %2

@ECHO Step 4: Dropping Tables.
sqlcmd -E -i IndexCreate.sql -S %1 -d %2

@ECHO .
@ECHO Database Teardown Complete
  